package com.baizhi.serviceImpl;

import com.baizhi.dao.LogDao;
import com.baizhi.dto.PageDTO;
import com.baizhi.entity.Log;
import com.baizhi.service.LogService;
import com.baizhi.vo.CommonVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
public class LogServiceImpl extends ServiceImpl<LogDao, Log> implements LogService {

    @Autowired
    private LogDao logDao;

    /**
     * 分页查所有日志
     *
     * @param pageDTO
     */
    @Override
    public CommonVO queryPage(PageDTO pageDTO) {
        Page<Log> page = new Page<>(pageDTO.getPage(), pageDTO.getPageSize());
        Page<Log> logPage = logDao.selectPage(page, null);
        return new CommonVO(pageDTO.getPage(), logPage.getTotal(), logPage.getRecords());
    }

    /**
     * 添加日志
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public void  insert(Log log) throws RuntimeException{
        System.out.println(log);
        int insert = logDao.insert(log);
        System.out.println("insert = " + insert);
    }


}